<?php
include_once("../include/init.php");
include_once("../include/base.php");
//展示产品分类
$sql = "select * from tk_product_category";
$re = mysql_query($sql);
$info=[];
if(mysql_num_rows($re)>0){
		while ($arr = mysql_fetch_assoc($re)) {
		$info[] = $arr;
	}
}

$sql = "select * from tk_product";
	//搜索查询
	if(isset($_GET['sub'])){
	 		 $sosuo = trim($_GET['sosuo']);

	 		//判断是哪个查询
	 		$sql.= " where ";//组装SQL语句
	 	 if($sosuo != ""){
	 	 	$sql.= " pname like '%{$sosuo}%' and";

	 	 }
	 	 	$sql = substr($sql,0,-4);
	 	 	$url = "&pname={$sosuo}&sub=搜索";	
  	}

	//分页
	$totalRows= mysql_num_rows(mysql_query($sql));
	$pageRows = 9;
	$totalpage= ceil($totalRows / $pageRows);
	$page = isset($_GET['page'])?$_GET['page']:1;
	if($page <= 0 ||$page >$totalpage ||!is_numeric($page)){
		$page = 1;
	}
	$limitStart =$pageRows *($page -1);
	$sql.= " order by pid desc limit {$limitStart},{$pageRows}";
	$res = mysql_query($sql);
	$list=[];
	if(mysql_num_rows($res)>0){
		while ($arr = mysql_fetch_assoc($res)) {
		$list[] = $arr;
	}
}
?>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title><?php echo $cfg_title;?></title>
		<meta name="description" content="<?php echo $cfg_description;?>"/>
		<meta name="keywords" content="<?php echo $cfg_keywords;?>"/>
		<link rel="stylesheet" href="../public/css/index.css"/>		
	</head>
	<body>
		<!-- 头部-->
<?php
include_once("header.php");
?>
		<!-- 主体-->

		<div class="content">
			<div class="content_top">
				<ul>
					<li><a href="">品牌:</a></li>
					<li><a href="">全部</a></li>				
					<?php foreach($info as $vo){?>
					<li><a href=""><?= $vo['cate_name']?></a></li>
					<?php }?>
				</ul>
			</div>
			<hr>

			<div class="content_center">
			
				<?php foreach($list as $vk){ 
					if($vk['ifshow']==1){
				?>
				
				<div class="cours">
					<img src="<?=$vk['thumb']?>" width="250px" >
					<span class="price">￥<?=$vk['price']?>.00</span>
					<span><a href="product.php?id=<?=$vk['pid'] ?>"><?=$vk['descp']?> </a></span>			
					<span class="left">库存：<?=$vk['snums']?></span>
					<span class="right">地址：<?=$vk['addr']?></span>
				</div>
				<?php }else{ ?>

				<?php } }?>
			</div>		
			<div class="pagelistbox">
					<span>共<?php echo $totalpage;?>页/<?php echo $totalRows;?>条记录 </span>
					<span class='indexPage'><a href="?page=1">首页 </a>
					<a class='prevPage' href='?page=<?php echo $page-1?>'>上页</a> 
					</span>
					<?php for($i=1;$i<=$totalpage;$i++):?>
						<?php if($i == $page):?>
							<strong><?php echo $i;?></strong>
							<?php else:?>
							<a href='?page=<?php echo $i;?>'><?php echo $i;?></a>
						<?php endif;?>
					<?php endfor;?>
					<a class='nextPage' href='?page=<?php echo $page+1;?>'>下页</a> 
					<a class='endPage' href='?page=<?php echo $totalpage;?>'>末页</a> 
			</div>
		</div>
			<hr>
		<div class="clearfix"></div>
			<!-- 页脚-->
			<?php
             include_once("footer.php");
             ?>
		
	</body>
</html>
